package com.bit101.components
{
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.net.URLRequest;
	
	public class ImageButton extends Sprite
	{
		private var drop:DropShadowFilter = new DropShadowFilter(10,45,0,0.5);
		public var data:Object;
		public function ImageButton(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0,
									width:Number=0,height:Number=0,sourceurl:String=null,defaultHandler:Function = null)
		{
			//var img:Bitmap = new source;
			//addChild(img);
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
			loader.load(new URLRequest(sourceurl));
			addChild(loader);
			//this.width = width;
			//this.height = height;
			this.x = xpos;
			this.y = ypos;
			parent.addChild(this);
			this.addEventListener(MouseEvent.ROLL_OVER,onMouseOver);
			this.addEventListener(MouseEvent.ROLL_OUT,onMouseOut);
			if(defaultHandler != null)
			{
				addEventListener(MouseEvent.CLICK, defaultHandler);
			}
		}
		public function onMouseOver(event:MouseEvent):void{
			this.y --;
			this.filters = [drop]
		}
		public function onMouseOut(event:MouseEvent):void{
			this.y ++;
			this.filters = null;
		}
		public function onComplete(evnet:Event):void{
			this.dispatchEvent(new Event(Event.RESIZE));
		}
		
		
		
	}
}